package main;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Canvas_ extends Application {
	
	static GraphicsContext gc;
	
	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {	
		
		Canvas can = new Canvas();
		can.setHeight(200);
		can.setWidth(200);
		
		gc = can.getGraphicsContext2D();
		
		HBox hBox = new HBox();

		Button button1 = new Button("Funktion 1");
		Button button2 = new Button("Funktion 2");
		
		button1.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent arg0) {
				gc.setFill(Color.BURLYWOOD);
				gc.fillRect(50, 50, 50, 50);
			}
		});
		
		button2.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent arg0) {
				gc.clearRect(0, 0, gc.getCanvas().getHeight(), gc.getCanvas().getWidth());
				
			}
		});
		
		hBox.getChildren().addAll(button1, button2);
		hBox.setSpacing(10); // Zweite variante Spacing
		hBox.setPadding(new Insets(10, 10, 10, 10));
		
		// Layout
		BorderPane pane = new BorderPane();
		
		// abstand Zwischen Top und dem Rest
		pane.setTop(hBox);
		pane.setCenter(can);
		
		// Fensterinhalt
		Scene scene = new Scene(pane);
		
		stage.setTitle("JavaFX Frame");
		stage.centerOnScreen();
		
		stage.setHeight(500);
		stage.setWidth(600);
		
		// Oder
		// stage.setX();
		// stage.setY();
		
		// Minimum Hight und width
		stage.setMinHeight(150);
		stage.setMinWidth(150);
		
		stage.setScene(scene);
		
		stage.show();
	}
	
	/**
	 * 
	 * @param x
	 */
	private void changeStyle(Label... x){
		for (Label l : x) {
			l.setStyle("-fx-background-color: #90CCFC;");
		}
	}

}
